﻿using DAL.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL.Persistencia
{
    public class SupplierAmenityDAL
    {
        private NewTierraEntities Con;

        public SupplierAmenityDAL()
        {
            Con = new NewTierraEntities();
        }

        public int ObterID(int SupplierID, int AmenityID)
        {
            try
            {
                var supAm = Con.S_SupplierAmenities.Where(a => a.S_SupplierAmenities_Amenities_ID == AmenityID && a.S_SupplierAmenities_Supplier_ID == SupplierID).SingleOrDefault();

                if (supAm == null)
                    return 0;
                else
                    return supAm.S_SupplierAmenities_ID;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public List<S_SupplierAmenities> ListarTodos()
        {
            try
            {
                return Con.S_SupplierAmenities.OrderBy(a => a.S_SupplierAmenities_ID).ToList();
            }
            catch
            {
                throw;
            }
        }

        public List<S_SupplierAmenities> ListarPorSupplier(int SupplierID)
        {
            try
            {
                return Con.S_SupplierAmenities.Where(a => a.S_SupplierAmenities_Supplier_ID == SupplierID).OrderBy(b => b.S_SupplierAmenities_ID).ToList();
            }
            catch
            {
                throw;
            }
        }

        public void Inserir(S_SupplierAmenities supAm)
        {
            try
            {
                Con.AddToS_SupplierAmenities(supAm);
                Con.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void Excluir(int ID)
        {
            try
            {
                S_SupplierAmenities supAm = Con.S_SupplierAmenities.Where(a => a.S_SupplierAmenities_ID == ID).Single();

                Con.DeleteObject(supAm);
                Con.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}
